package secondkill.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;

/**
 * MD5工具类
 * @Auther  丁子川
 * @create 2022/1/12 17:30
 */
@Component
public class MD5Util {
    public static String MD5(String src){
        return DigestUtils.md5Hex(src);
    }
    //MD5盐
    private static final String salt ="1a2b3c4d";

    public static String inputPass_To_FormPass(String inputPass){
        String str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        return MD5(str);
    }
    public static String formPass_To_DBPass(String formPass,String salt){
        String str = "" + salt.charAt(0) + salt.charAt(2) + formPass + salt.charAt(5) + salt.charAt(4);
        return MD5(str);
    }
    public static String inputPass_To_DBPass(String inputPass,String salt){
        String fromPass = inputPass_To_FormPass(inputPass);
        return formPass_To_DBPass(fromPass,salt);
    }

    public static void main(String[] args) {
        System.out.println(inputPass_To_FormPass("Dzy001016"));
        System.out.println(formPass_To_DBPass("69c4e5ca0019e331d3eca73eff26202e","1a2b3c4d"));
        System.out.println(inputPass_To_DBPass("Dzy001016","1a2b3c4d"));
    }
}
